package com.uchedao.vehicledetection.loadstate.listview.footview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.uchedao.vehicledetection.R;
import com.uchedao.vehicledetection.inf.ILoadResult;

/**
 * ListView底部
 * 
 * @author linbinghuang
 *
 */
public class FootView extends BaseFootView implements ILoadResult {

	/**
	 * 等待
	 */
	protected TextView mloadingPb;
	/**
	 * 全部加载完成
	 */
	protected TextView mLoadCompTv;

	/**
	 * 空提示
	 */
	protected TextView mLoadEmptyTv;

	public FootView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}


	public FootView(Context context) {
		super(context);
		init();
	}

	/**
	 * 初始化
	 */
	private void init() {

		LayoutParams mLayoutParams = new LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
		View view = getLayout();
		mLayoutParams.gravity = Gravity.CENTER;
	
		addView(view, mLayoutParams);
		mloadingPb = (TextView) findViewById(R.id.load_ing_pb);
		mLoadCompTv = (TextView) findViewById(R.id.load_complete_tv);
		mLoadEmptyTv = (TextView) findViewById(R.id.load_empty_tv);
		mLoadEmptyTv.setOnClickListener(mClickListener);
	}

	public View getLayout(){
	    return LayoutInflater.from(getContext()).inflate(
	            R.layout.foot_view, null);
	}
	@Override
	public void onLoadFailed() {
		dispathShowView(mLoadEmptyTv);
	}

	@Override
	public void onLoadSuccess() {
//		dispathShowView(mloadingPb);
	}

	@Override
	public void onLoadComplete() {
		dispathShowView(mLoadCompTv);
	}

	@Override
	public void onLoadEmpty() {
		dispathShowView(mLoadEmptyTv);
	}

	@Override
	public void onLoadStart() {
		dispathShowView(mloadingPb);
	}

	/**
	 * 显示哪个view
	 * 
	 * @param v
	 */
	protected void dispathShowView(View v) {

		if (mloadingPb.getId() == v.getId()) {
			mloadingPb.setVisibility(View.VISIBLE);
			mLoadCompTv.setVisibility(View.GONE);
			mLoadEmptyTv.setVisibility(View.GONE);
			return;
		}
		if (mLoadCompTv.getId() == v.getId()) {
			mloadingPb.setVisibility(View.GONE);
			mLoadCompTv.setVisibility(View.GONE);
			mLoadEmptyTv.setVisibility(View.GONE);
			return;
		}
		if (mLoadEmptyTv.getId() == v.getId()) {
			mloadingPb.setVisibility(View.GONE);
			mLoadCompTv.setVisibility(View.GONE);
			mLoadEmptyTv.setVisibility(View.VISIBLE);
			return;
		}
	}

	private OnClickListener mClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			if (v.getId() == mLoadEmptyTv.getId()) {
				if (mCallBack != null) {
					mCallBack.onUpLoad();
				}
			}
		}
	};

	

	

	

}
